/**
 * 
 */
package com.gragra.benchmark;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import cern.colt.Arrays;
/**
 * format for data is int its,int threads, double smoothing, double weight, int depth, int averagingRounds,int samplingSetOff
 * @author Christoph Teichmann
 * 20.09.2013
 */
public abstract class RunBenchmarkMultipleTimes
{
	/**
	 * @throws IOException 
	 * 
	 */
	public RunBenchmarkMultipleTimes(BufferedReader lines,BufferedReader golds, BufferedReader parameters,BufferedWriter output) throws IOException
	{
		ObjectArrayList<double[]> paras = makeParameters(parameters);
		String line;
		while((line = lines.readLine()) != null)
		{
			String goldOne = golds.readLine();
			String goldTwo = golds.readLine();
			for(double[] d : paras)
			{
				MakeBenchmark mb = new MakeBenchmark(line, goldOne, goldTwo, makeCreators((int) d[1]),(int) d[0],(int) d[1], d[2], d[3],(int) d[4],(int) d[5],(int) d[6]);
				output.newLine();
				output.newLine();
				output.write(line);
				output.newLine();
				output.write(goldOne);
				output.newLine();
				output.write(goldTwo);
				output.newLine();
				output.write(Arrays.toString(d));
				output.write("\r\n");
				mb.writeOutResults(output);
				output.flush();
			}
		}
	}
	/**
	 * 
	 * @return
	 */
	protected abstract CreateCorpusAndGoldAssigner[] makeCreators(int threads);
	/**
	 * 
	 * @param parameters
	 * @return
	 * @throws IOException 
	 */
	private ObjectArrayList<double[]> makeParameters(BufferedReader parameters) throws IOException
	{
		String line;
		ObjectArrayList<double[]> list = new ObjectArrayList<double[]>();
		while((line = parameters.readLine()) != null)
		{
			String[] parts = line.split("\\s+");
			double[] d = new double[parts.length];
			for(int i=0;i<d.length;++i)
			{d[i] = Double.parseDouble(parts[i]);}
			list.add(d);
		}
		return list;
	}
}